<?php

class Formulario{
	
	private $_itens = array();
	private $_id = null;
	private $_method = null;
	private $_action = null;
	
	public function __construct($id, $method, $action){
		
		$this->_id = $id;
		$this->_method = $method;
		$this->_action = $action;
	}
	
	public function addItem($label, $item){
		$this->_itens[] = array('label'=>$label, 'value'=>$item);
	}
	
	public function addHidden($item){
		$this->_itens[] = array('hidden'=>$item);
	}
	
	public function getItens(){
		return $this->_itens;
	}
	
	public function dump($html_obj = null){
		
		if(!$html_obj){
			$html_obj = $GLOBALS['html_obj'];
		}
		
		$form = '<form method="%s" id="%s" action="%s">';
		$form = sprintf($form, $this->_method, $this->_id, $this->_action);
		$html_obj->addContent($form);
		
		$html_obj->addContent('<center>');
		foreach($this->_itens AS $item){
			
			if($item['label']){
				$html_obj->addContent($item['label']);
			}
			
			if($item['value']){
				
				$html_obj->addContent($item['value']);
				$html_obj->addContent('<br />');
			}else if($item['hidden']){
				$html_obj->addContent($item['hidden']);
			}
		}			
		$html_obj->addContent('</center>');
		$form = '</form>';
		$html_obj->addContent($form);

		$html_obj->dump();
	}
}